var isSecond = true;
var shopData;
var system = {
	ipad: false
};

system.ipad = (navigator.userAgent.match(/iPad/i) != null) ? true : false;


$(function() {
            $(".common_contentBlock").animate({
                opacity: 1
            }, 1000);
            var showNav = function() {
                $(".nav_button").addClass("current");
                $(".nav_bg,.navBlock_contnet").addClass("current").stop(true, true).fadeIn(500);
            }
            var hideNav = function() {
                $(".nav_button").removeClass("current");
                $(".nav_bg,.navBlock_contnet").removeClass("current").stop(true, true).fadeOut(500);
            }
            $(".nav_button").bind("click", function() {
                changeSelect(-1)
                if ($(".nav_button").hasClass("current")) {
                    hideNav();
                } else {
                    showNav();
                }
            });
        })

        function swiperIndex() {
            $(".nav_button").addClass("fff");
            $(".nav_backButton").css({
                "display": "none"
            });
            //全屏定高
            var wHeight = $(window).height();
            $(".swiper-container").css({
                "height": wHeight
            });

            //横向切换
            var on = 0;
            $(".home_block").eq(on).css({
                "display": "block"
            });
            var mySwiper = new Swiper('.swiper-container', {
                pagination: '.home_navBlock',
                //loop: true,
                onSlideChangeStart: function(swiper) {
                    on = swiper.activeIndex;
                    $(".home_block").css({
                        "display": "none"
                    });
                    $(".home_block").eq(on).css({
                        "display": "block"
                    });
                }
            })
        }

function setLayout(h) {
	var mapHtml = $("#mapID"),
		mapH = 360;
	if (h <= 480) {
		mapH = 240;
		maxDistance = 7500;
	} else if (h > 480 && h < 568) {
		mapH = 280;
		maxDistance = 7500;
	} else if (h >= 568 && h < 600) {
		mapH = 300;
		maxDistance = 8500;
	} else if (h > 667 && h <= 736) {
		mapH = 420;
		maxDistance = 9000;
	} else if (h > 736 && h <= 768) {
		mapH = 420;
		maxDistance = 9000;
	}  else if (h > 768 && h <= 812) {
		mapH = 420;
		maxDistance = 9000;
	} else if (h > 812 && h <= 1024) {
		mapH = 600;
		maxDistance = 9000;
	} else if (h > 1024 && h <= 1366) {
		mapH = 650;
		maxDistance = 15000;
	}
	mapHtml.css("height", mapH + "px");
	return mapH;
}

var maxDistance = 9000;
var selectedShop = 0,
	selectLetter = 0,
	selectedFloor = 0;

        function infoInit() {
            function checkRowNum(ah, sh, i) {
                var a = ah - sh * i;
                if (a > 0) {
                    checkRowNum(ah, sh, ++i);
                } else {
                    hn = i - 1;
                }
            }
            checkRowNum(lh, lih, 2);
            $("div[class='shop_list']").height(lh);

            $("div[class='searbox_mask']").unbind();
            $("div[class='searbox_mask']").bind('click', function () {
                changeSelect(-1);
            })

}

        function bindShopList(slist, bl) {
            $("#infoSwiper div").remove();
            $("#infoSwiper").css({ " transition-duration": "0", "transform": "translate3d(0px, 0px, 0px)" });
            if (slist.length == 0) {
                $("#infoSwiper").append('<div class="swiper-slide shop_list_01">' + '<div style="line-height: 50px;">暂时没有店铺</div>' + '</div>');
                swiper.reInit();
                return;
            }
            var thn = Math.ceil(slist.length / wn);//thn几行     wn是一行平均分布5个或10个等
            if (thn < hn) {
                hn = thn;    //如果几行小于hn的高度  就当做只有一个滑动页面固定行数hn   如果是slist有21个  每行10个   那就hn=2.1=3行
            }
            for (var i = 0, l = slist.length, tl; i < l; i = (i + wn * hn)) {
                var swiperHtmlStart = '<div class="swiper-slide shop_list_01">',
                    swiperHtmlEnd = '</div>',
                    swiperHtmlContent = '';
                if ((i + wn * hn) > l) {
                    tl = l;
                } else {
                    tl = i + wn * hn;
                }
                for (var j = i; j < tl; j++) {
                    var shopTName_ = '';
                    for (var k = 0; k < slist[j].ShopType.length; k++) {
                        if (shopTName_ == '')
                            shopTName_ = shopTName_ + slist[j].ShopType[k].ShopTypeFName;
                        else if (shopTName_ != slist[j].ShopType[k].ShopTypeFName)
                            shopTName_ = shopTName_ + '&' + slist[j].ShopType[k].ShopTypeFName;
                    }
                    var o = {
                        name: slist[j].Name,
                        areaName: slist[j].AreaName.toUpperCase(),
                        logo: slist[j].Logo,
                        pointID: slist[j].PointID,
                        shopTypeFName: shopTName_,
                        acreage: slist[j].Acreage
                    }
                    o = encodeURIComponent(JSON.stringify(o));
                    swiperHtmlContent = swiperHtmlContent + '<div onclick=selectClick("' + slist[j].PointID + '",false),mapMapinClick("' + o + '",true) class="shop_list_img" style=background-image:url("' + slist[j].Logo + '")></div>';
                }
                $("#infoSwiper").append(swiperHtmlStart + swiperHtmlContent + swiperHtmlEnd);
            }

	mw = (w - liw * wn) / (wn + 1);
	$("div[class='shop_list_img']").css("margin-left", mw);
	mh = (lh - lih * hn) / (hn + 1);
	$("div[class='shop_list_img']").css("margin-top", mh);
	if (bl) {
		swiper = new Swiper('.swiper-container', {
			initialSlide: 0,
			observer: true, //修改swiper自己或子元素时，自动初始化swiper
			observeParents: true //修改swiper的父元素时，自动初始化swiper
		})
	} else {
		 swiper.reInit();
	}
}

        function changeSelect(n) {
            $("div[class='searbox_mask']").css("display", "none");
            var $select = $("div[class='info_select']"),
                $l = $select.children().length;
            for (var i = 0; i < $l; i++) {
                $select.find("a").eq(i).removeClass();
                if (i == n) {
                    $("#showbox_" + i).css("display") == "block" ? $select.find("a").eq(i).addClass("info_a") && $("#showbox_" + i).css("display", "none") : $select.find("a").eq(i).addClass("info_b") && $("#showbox_" + i).css("display", "block") && $("div[class='searbox_mask']").css("display", "block");
                } else {
                    $select.find("a").eq(i).addClass("info_a");
                    $("#showbox_" + i).css("display", "none");
                }
            }
        }

function bindFloor(data, n) {
	//console.log(data)
	var ul = $("#showbox_0 ul"),
		liHtml = '';
	ul.find("li").remove();
	for (var i = 1; i < data.length; i++) {
		// for (var i = data.length - 1; i >= 0; i--) {
		liHtml = liHtml + '<li name=' + data[i].FloorID + ' onclick=changeFloor("' + data[i].FloorID + '","' + data[i].Name + '","' + (i - 1) + '")><span class="selected"></span><em>' + data[i].Name + '</em></li>';
		i == n ? $("div[class='info_select_01']").eq(0).find('span').html(data[i].Name) : !1;
	}
	ul.append(liHtml);
	ul.find("li").eq(n-1).find("span").eq(0).css("background-image", "url(../images/d_1.png)");
	bingdtouch(ul);
}

function bingdtouch(l) {
	l.delegate('li', 'touchstart', function (e) {
		e.target.className = 'activelis';
	});
	l.delegate('li', 'touchend', function (e) {
		e.target.className = 'activelie';
	});
}
// 切换楼层
function changeFloor(id, name, j) {
	// console.log(id)
	// console.log(name)
	j = j * 1 + 1 * 1
	// console.log(j)
	var $li = $("#showbox_0 ul li");
	for (var i = 0, len = $li.length; i < len; i++) {
		i == j ? $li.eq(i).find("span").eq(0).css("background-image", "url(../images/d_1.png)") : $li.eq(i).find("span").eq(0).css("background", "");
	};
	// console.log(i)
	// console.log(j)
	changeSelect(0);
	$("div[class='info_select_01']").eq(0).find('span').html(name);
	self.map.showFloors([id])
	self.map.zoomLevel(15);
	self.map.setPolarAngle(40);
	self.map.setAzimuthalAngle(0)
	self.map.move2Point({
		x: 500,
		y: -100
	});
	selectedFloor = id;
	setShopList({
		type: 'f',
		id: id
	})
}

function bindShop(data) {
	var ul = $("#showbox_1 ul"),
		liHtml = '<li onclick=changeShop("all","全部","0")><span class="selected"></span><em>全部</em></span></li>';
	ul.find("li").remove();
	var len = data.length,
		shopList = ["主力店", "零售", "餐饮", "娱乐", "教育", "其他"]
	dataNew = [];
	for (var j = 0; j < shopList.length; j++) {
		for (var i = 0; i < len; i++) {
			if (data[i].type == shopList[j]) {
				dataNew.push(data[i]);
				break;
			}
		}
	}

	for (var i = 0, len = dataNew.length; i < len; i++) {
		var type = encodeURIComponent(dataNew[i].type);
		var n = Number(i) + 1;
		liHtml = liHtml + '<li name=' + dataNew[i].type + ' onclick=changeShop("' + type + '","' + shopList[i + 1] + '","' + n + '")><span class="selected"></span><em>' + dataNew[i].type + '</em></li>';
	}

	ul.append(liHtml);
	ul.find("li").eq(0).find("span").eq(0).css("background-image", "url(../images/d_1.png)");
	bingdtouch(ul);
}

function changeShop(type, name, j) {
	var $li = $("#showbox_1 ul li");

	for (var i = 0, len = $li.length; i <= len; i++) {
		//console.log(j)
		(i - 1) == j ? $li.eq(i - 1).find("span").eq(0).css("background-image", "url(../images/d_1.png)") : $li.eq(i - 1).find("span").eq(0).css("background", "");
	};
	changeSelect(1);
	$("div[class='info_select_01']").eq(1).find('span').html(name);
	type = decodeURIComponent(type);
	setShopList({
		type: 's',
		id: j
	});
}

function changeLetter(l) {
	var $li = $("#showbox_2 ul li");
	for (var i = 0, len = $li.length; i <= len; i++) {
		(i - 1) == l ? $li.eq(i - 1).find("span").eq(0).css("background-image", "url(../images/d_1.png)") : $li.eq(i - 1).find("span").eq(0).css("background", "");
	};
	changeSelect(2);
	var getValue = $(".getVlaue").eq(l).html();
	$("div[class='info_select_01']").eq(2).find('span').html(getValue);
	setShopList({
		type: 'l',
		id: l
	})
}

function mapMapinClick(ob, bl) {
	 console.log(JSON.parse(decodeURIComponent(ob)))
	bl ? ob = JSON.parse(decodeURIComponent(ob)) : ob;
	$("div[class='info_icon']").css("display", "none");
	$("div[class='info_shopDetail']").css("display", "block");
	ob.shopName == '' ? $("div[class='info_shopDetail_01 info_shopDetail_name']").html('暂无') : $("div[class='info_shopDetail_01 info_shopDetail_name']").html(ob.name);
	$("div[class='info_shopDetail_01 info_shopDetail_ct']").find('span').eq(0).html(ob.areaName);
	ob.shopLogo == '' ? $("div[class='info_shops_logo']").css("background-image", "") && $("div[class='info_shops_logo']").html('待租') : $("div[class='info_shops_logo']").html('') && $("div[class='info_shops_logo']").css("background-image", "url(" + ob.logo + ")").css("background-color", "white");
	ob.shopTypeFName == '' ? $("div[class='info_shopDetail_01 info_shopDetail_po']").html('暂无') : $("div[class='info_shopDetail_01 info_shopDetail_po']").html(ob.shopTypeFName);
	$("div[class='info_shopDetail_01 info_shopDetail_ct']").find('span').eq(1).html(shopData.acreage + '㎡');;
}


var config = {
	pid: "1095415A-2977-4421-B59E-DA1B7E0F2D21",
	//          pid: "1E83BB66-B860-4CBB-8D0F-ADB556981E3F",
	projectID: '',
	showFloorNumber: 1,
	orderFloors: {},
	area: {},
	list: '',
	lists: "",
	getServeData: function (data, fn) { //获取数据
		$.ajax({
			type: "GET",
			url: config.url,
			data: data,
			dataType: "JSONP",
			success: function (s) {
				fn(s);
				// console.log(data)
			}
		});
	},
	url: "https://map.ckiosk.cn/webAPI/ClientService.asmx/Command?callback"
}

function init() {

	GIM.SHOW_SPRITE_LENGTH = 5500 * 2;
	GIM.SHOW_Facility_LENGTH = 4000 * 2;
	GIM.REMOTE_SERVER = "https://map.ckiosk.cn/webAPI/ClientService.asmx/Command?callback"
	GIM.FLOOR_GAP = 800;
	GIM.DEBUG_MODE = false;
	GIM.far = 8000;
	//          GIM.PID = config.projectID
	//          GIM.INIT_FLOORID = "47A48619-7420-4FD5-AF29-7ABDF6A10947";
	var container = document.getElementById('mapID')
	container.style.cssText = "width:" + (container.clientWidth / 1) + "px;height:" + (container.clientHeight / 1) + "px;overflow: hidden;text-align:right";
	var params = {
		initCompleted: initCompelte,
		onSelected: onSelected,
		container: container,
		themeID: "1003",
		accessToken: "86E81446-7C98-432F-B991-889FB1FA3F11",
		backgroundColor: '#f2f2f2',
		projectID: 'D79C2C4F-1908-45E6-B129-7B031C05381F',
		//				initFloorID: object.floorid,
		cloudID: '1095415A-2977-4421-B59E-DA1B7E0F2D21',
		showLabelType: "Name",
		labelScale: 2.5, //文本缩放值
		// showLabelType: "No.", //默认显示店铺号，可以选
	}
	self.map = new GIM.Map3D(params);
	self.map.selectedColor = 0x981c29;
	self.map.showCompass = false;

	if (system.ipad) {
		self.map.zoomLevel(12);
	} else {
		self.map.zoomLevel(18);
	}

	self.map.setPolarAngle(40);
	self.map.setAzimuthalAngle(0)
	self.map.move2Point({
		x: 600,
		y: -100
	});
}


function initCompelte(floorData) {
	// console.log(data.v)
	$("#loadings").hide()
	config.list = GIM.DisplayModel.prototype.allArea;
	floorData = floorData.sort(function (a, b) {
		return a.order - b.order
	});
	floorData.forEach(function (t) {
		config.orderFloors[t.order - 17] = t.floorID
	})
	// self.map.showFloors([config.orderFloors[config.showFloorNumber]]);
	$(".loadingBox").css('display', 'none');
	// bindShopList()
	// getLastData()
	// setTimeout(() => {
	// 	self.map.showFloors(["9DDCC5F1-437F-4AA0-A041-5389E190F8E4"])
	// 	setShopList({
	// 		type: 'f',
	// 		id: "9DDCC5F1-437F-4AA0-A041-5389E190F8E4"
	// 	})
	// }, 0);
	setTimeout(function () {
		self.map.showFloors(["9DDCC5F1-437F-4AA0-A041-5389E190F8E4"])
		setShopList({
			type: 'f',
			id: "9DDCC5F1-437F-4AA0-A041-5389E190F8E4"
		})
	}, 0)
}

function onSelected(data) {
	console.log(data)
	shopData = data
	// $(".info_shopDetail").show()
	// $(".info_icon").hide()
	// self.map.setPolarAngle(15);
	var o = {}
	var lists = config.lists
	var sameNo = 0;
	lists.forEach(function (Element) {
		if (Element.PointID == data.nodeId) {
			// console.log("a")
			sameNo = sameNo + 1
			o = {
				name: Element.Name,
				areaName: Element.AreaName.toUpperCase(),
				logo: Element.Logo,
				pointID: Element.PointID,
				shopTypeFName: Element.ShopType[0].ShopTypeFName,
				acreage: data.acreage
			}
			o = encodeURIComponent(JSON.stringify(o));
			mapMapinClick(o, true);
		} else if (sameNo < 1) {
			// console.log("b")
			o = {
				name: "暂无",
				areaName: data.name.toUpperCase(),
				logo: './../images/null.jpg',
				pointID: Element.PointID,
				shopTypeFName: "",
				acreage: data.acreage
			}
			o = encodeURIComponent(JSON.stringify(o));
			mapMapinClick(o, true);
		}
	})

	// object.flag = true;
	// object.mark = data.areaID;
	// object.isShare = true;

	// $('#text').val(data.EnName)
	// self.map.regNavigationPause(function () { //暂停模拟导航的时候触发
	// 	$(".mo_center").html("继续导航")
	// 	$(".scale").show()
	// 	isPause = true;
	// })
	// self.map.toggleSimulate()
	// $('.mo_daohang,.mo_tishi').slideUp('slow');
	// $('.pointName').html(data.EnName ? data.EnName : data.name);
	// $('.pointFloor').html(object.flooridFloors[data.floorID]);
	// nowFloorToggleNo = object.flooridFloors[data.floorID]
	// FloorDetection()
	// setStart = function () {
	// 	$('.operation').css('display', 'block');
	// 	$('.compass').css({
	// 		'top': '2.05rem'
	// 	})
	// 	$('#startPoint').val(object.flooridFloors[data.floorID] + ' ' + ' ' + ' ' + (data.EnName ? data.EnName : data.name));
	// 	object.startPP = object.flooridFloors[data.floorID];
	// 	console.log()
	// 	object.areaID = data.areaID;
	// 	object.xlId.startId = data.areaID;
	// 	object.moFloorid.start = data.floorID;
	// 	object.moFloorid.startArea = data.EnName;
	// 	object.startP = self.map.setStartArea(data.areaID, true);
	// 	object.ispoint = false;
	// 	object.isStart = false
	// 	if (object.endP == '' || object.endP == null) {
	// 		$('.tishi').html('请设置终点');

	// 		$('.go,.mogo').attr("disabled", 'disabled').css('backgroundColor', '#999');
	// 	} else {
	// 		$('.tishi').html('点击开始导航');
	// 		$('.mogo').removeAttr("disabled").css('backgroundColor', '#a6937c');
	// 		$('.go').removeAttr("disabled").css('backgroundColor', '#999');
	// 	}
	// 	$('.operation').css('display') == 'block' ? $('.gSearch').hide() : $('.gSearch').show()
	// 	$('.operation').css('display') == 'block' ? $('.nav_qyfg').hide() : $('.nav_qyfg').show()
	// 	pathGo()
	// }
	// setEnd = function () {
	// 	$(".operation").css('display', 'block')
	// 	object.xlId.endId = data.areaID;
	// 	object.moFloorid.end = data.floorID
	// 	$('#endPoint').val(object.flooridFloors[data.floorID] + ' ' + ' ' + ' ' + (data.EnName ? data.EnName : data.name));
	// 	object.moFloorid.endArea = data.EnName
	// 	object.endPP = object.flooridFloors[data.floorID]
	// 	$('.compass').css({
	// 		'top': '2.05rem'
	// 	})
	// 	$('.tishi').html('点击开始导航');
	// 	object.isEnd = false
	// 	object.endP = self.map.setEndArea(data.areaID, true);
	// 	if (object.startP == '' || object.startP == null) {
	// 		$('.tishi').html('请设置起点');
	// 		$('.go,.mogo').attr("disabled", 'disabled').css('backgroundColor', '#999');
	// 	} else {
	// 		$('.tishi').html('点击开始导航');
	// 		$('.mogo').attr("disabled", false).css('backgroundColor', '#a6937c');
	// 		$('.go').attr("disabled", false).css('backgroundColor', '#999');
	// 	}
	// 	$('.operation').css('display') == 'block' ? $('.gSearch').hide() : $('.gSearch').show()
	// 	pathGo()
	// }
}

function getSysConfig() {
	var datas = {
		"code": "{pid:'" + config.pid + "',lan:'SC',command:'GetMallCityProjectConfig',parameter:{'ShopInfo':''}}"
	}; //获取配置信息
	// 整个项目(店铺)数据
	config.getServeData(datas, function (data) {
		if (data.c == 200 && data.v.length > 0) {
			data = data.v[0];
			//console.log(data)
			config.projectID = data.ProjectID;
			bindFloor(data.Floor, config.showFloorNumber);
			getshops(data.ProjectID);
			bingdtouch($("#showbox_2 ul"));
			init();
		} else {
			alert("获取配置信息错误!");
		}
	});
}

function getClick(type) {
	var clickMark = '';
	switch (type) {
		case 0:
			clickMark = 'ZSSC#Home';
			break;
		case 1:
			clickMark = 'ZSSC#overview';
			break;
		case 2:
			clickMark = 'ZSSC#info';
			break;
		case 3:
			clickMark = 'ZSSC#contact';
			break;
	}
	var datas = {
		"code": "{pid:'" + config.pid + "',lan:'SC',command:'addClick',parameter:{'BrandID':'','AreaID':'','ClickMark':'" + clickMark + "'}}"
	}; //获取配置信息
	config.getServeData(datas, function (data) {});

}

function getshops(id) {
	var datas = {
		"code": "{pid:'" + id + "',lan:'SC',command:'getShops',parameter:{'HideField':'Introduction,Email'}}"
	}

	// 获取店铺数据
	config.getServeData(datas, function (data) {
		// console.log(data)
		if (data.c == 200 && data.v.length > 0) {
			config.lists = data.v
			 console.log(config.lists)
			sessionStorage.setItem("ShopsData", JSON.stringify(data.v));
			data = data.v;

			for (var i = 0; i < data.length; i++) {
				_shopType(i);
				_letter(i);
			}
			letters = letters.concat(letter_1, letter_2, letter_3, letter_4, letter_5);
			letters_s.push(letter_1);
			letters_s.push(letter_2);
			letters_s.push(letter_3);
			letters_s.push(letter_4);
			letters_s.push(letter_5);

			bindShop(shop);
			$("#showbox_2 span").eq(0).css("background-image", "url(../images/d_1.png)");

			function _shopType(i) {
				if (shop.length == 0) {
					for (var j = 0; j < data[i].ShopType.length; j++) {
						var _shop = {
							data: [],
							type: ''
						};
						if (shop.length == 0) {
							_shop.type = data[i].ShopType[j].ShopTypeFName;
							_shop.data.push(data[i]);
							shop = shop.concat(_shop);
						} else {
							pushShop();
						}
					}
				} else {
					pushShop();
				}

				function pushShop() {
					if (data[i].ShopType == undefined)
						return;
					for (var j = 0; j < data[i].ShopType.length; j++) {
						for (var k = 0; k < shop.length; k++) {
							var _shop = {
								data: [],
								type: ''
							};
							if (data[i].ShopType[j].ShopTypeFName == shop[k].type) {
								for (var m = 0; m < shop[k].data.length; m++) {
									if (data[i].AreaID == shop[k].data[m].AreaID) {
										break;
									} else {
										while (m == shop[k].data.length - 1) {
											shop[k].data.push(data[i]);
											break;
										}
									}
								}
								break;
							} else {
								while (k == shop.length - 1) {
									_shop.type = data[i].ShopType[j].ShopTypeFName;
									_shop.data.push(data[i]);
									shop = shop.concat(_shop);
								}
							}
						}
					}
				}
			}

			function _letter(i) {
				var l = data[i].FirstLetter.toUpperCase();
				switch (l) {
					case "A":
					case "B":
					case "C":
					case "D":
					case "E":
						setLetter(letter_1);
						break;
					case "F":
					case "G":
					case "H":
					case "I":
					case "J":
						setLetter(letter_2);
						break;
					case "K":
					case "L":
					case "M":
					case "N":
					case "O":
						setLetter(letter_3);
						break;
					case "P":
					case "Q":
					case "R":
					case "S":
					case "T":
						setLetter(letter_4);
						break;
					case "U":
					case "V":
					case "W":
					case "X":
					case "Y":
					case "Z":
						setLetter(letter_5);
						break;
				}

				function setLetter(name) {
					if (name.length == 0) {
						name.push(data[i])
					} else {
						for (var j = 0; j < name.length; j++) {
							if (data[i].AreaID == name[j].AreaID) {
								break;
							} else {
								while (j == name.length - 1) {
									name.push(data[i]);
								}
							}
						}
					}
				}
			}
			setShopList();
		} else {
			console.log("获取店铺信息错误!");
		}
	});
}
var selectFid = ''

function setShopList(t) {
	// console.log(t)
	$("div[class='info_icon']").css("display", "block");
	$("div[class='info_shopDetail']").css("display", "none");

	if (t == undefined) {
		t = {};
		t.type = 0;
		var li_f = $("#showbox_0 li");
		selectFid = li_f.eq(2).attr("name");
	} else {
		// if (self.map != undefined)
		// self.map.clearselectUnit3D();
	}
	var fid, sname, lname, lastList = [];
	switch (t.type) {
		case "f":
			selectFid = t.id;
			getLastData(selectFid, selectedShop, selectLetter);
			break;
		case "s":
			selectedShop = t.id;
			getLastData(selectFid, selectedShop, lastList);
			// bindShopList(lastList);
			break;
		case "l":
			selectLetter = t.id;
			getLastData(selectFid, selectedShop, selectLetter);
			//bindShopList(lastList);
			break;
		default:
			getLastData(selectFid, 0, 0, true);
			//bindShopList(lastList, true);
			break;
	}
}

function getLetter_(data, fid) {
	var dl = [];
	data.forEach(function (d) {
		d.FloorID == fid ? dl.push(d) : !1;
	});
	return dl;
}

function getShop_(data, fid, n) {
	var dl = [];
	if (n == 0) {
		data.forEach(function (d) {
			d.data.forEach(function (ds) {
				if (ds.FloorID == fid) {
					dl.push(ds);
				}
			});
		});
	} else {
		n = $("#showbox_1 li").eq(parseInt(n)).attr("name");
		data.forEach(function (d) {
			if (d.type == n) {
				d.data.forEach(function (ds) {
					if (ds.FloorID == fid) {
						dl.push(ds);
					}
				});
			}
		});
	}
	dl = deleteDubleShop(dl);
	return dl;
}

function getLastData(fid, sn, ln, bl) {
	var s = [],
		l = [],
		all = [];
	if (ln == 0) {
		l = getLastData_l(letters, fid);
	} else {
		var ls = letters_s[ln - 1];
		l = getLastData_l(ls, fid);
	}
	s = getShop_(shop, fid, sn);
	l = getLetter_(l, fid);
	s.forEach(function (sd) {
		l.forEach(function (ld) {
			sd.AreaID == ld.AreaID ? all.push(ld) : !1;
		});
	});
	//return all;
	var floorDetailData = sessionStorage.getItem("floorDetailData" + fid);
	if (floorDetailData == "" || floorDetailData == null) {
		config.getServeData({
			"code": "{pid:'" + config.prejectID + "',lan:'SC',command:'getArea',parameter:{'FloorID':'" + fid + "'}}"
		}, function (data) {
			console.log(data)
			bindShopList_(data.v, all, bl);
			config.area = data.v
			console.log(data.v)
			sessionStorage.setItem("floorDetailData" + fid, JSON.stringify(data.v));
		});
	} else {
		config.area = JSON.parse(floorDetailData)
		// console.log(floorDetailData)
		bindShopList_(JSON.parse(floorDetailData), all, bl);
	}
}

function bindShopList_(adata, sdata, bl) {

	adata.forEach(function (a) {
		sdata.forEach(function (s) {
			if (a.AreaID == s.AreaID) {
				s.Acreage = a.Acreage;
			}
		})
	});
	bindShopList(sdata, bl);
}

function getLastData_l(l, fid) {
	var ls = [];
	l.forEach(function (d) {
		if (d.FloorID == fid) {
			ls.push(d);
		}
	});
	return ls;
}

function deleteDubleShop(array) {
	var r = [];
	for (var i = 0, l = array.length; i < l; i++) {
		for (var j = i + 1; j < l; j++)
			if (array[i] === array[j])
				j = ++i;
		r.push(array[i]);
	}
	return r;
}



function selectClick(aaa) {
	for (var key in config.list) {
		if (config.list[key].pointID == aaa) {
			self.map.cleanSelectUnit3D();
			console.log(config.list[key].areaID)
			self.map.selectUint3DByAreaId(config.list[key].areaID)
		}
	}
}


window.addEventListener("orientationchange", function () {
	// 宣布新方向的数值
	window.location.reload(true);
}, false);